var utils = require('/utils/index.js');
var base = require('/base_info.js');
Page({
  data: {
    userinfo: {},
    hotelInfo: {}
    // hotelInfo: JSON.parse(my.getStorageSync({
    //   key: 'hotel_info', // 缓存数据的key
    // }).data)
  },
  // 跳转到订单列表页面
  orderList (e) {
    my.navigateTo({
      url: './../order/order-list?index=' + e.currentTarget.dataset.index + '&id=' + e.currentTarget.dataset.id
    });
  },
  // 跳转到我的优惠券列表
  discount () {
    my.navigateTo({
      url: './../discount/discount'
    });
  },
  // 跳转到我的权益卡
  equity () {
    console.log(this.data.hotelInfo);
    my.navigateTo({
      url: './../equity-card/equity-card-list'
    });
  },
  // 跳转到个人评论列表
  comment () {
    my.navigateTo({
      url: './user-comment'
    });
  },
  // 获取data
  getData () {
    let that = this;
    that.setData({
      hotelInfo: JSON.parse(my.getStorageSync({
        key: 'hotel_info', // 缓存数据的key
      }).data)
    })
  },
  call () {
    my.makePhoneCall({ number: this.data.hotelInfo.tel });
  },
  onLoad(query) {
    // 页面加载
    let that = this;
    // 获取用户公开信息 
    my.getAuthCode({
      scopes: 'auth_user',
      success: (res) => {
        my.getAuthUserInfo({
          success: (userInfo) => {
            that.setData({
              userinfo: userInfo
            })
          }
        });
      }
    });
    var uid = my.getStorageSync({
      key: 'uid', // 缓存数据的key
    }).data;
    if (!uid || uid == "") {
      utils.getAuthCode(function(res){
        console.log(res);
        that.setData({
          userInfos: res.data.data
        })
        that.getData();
      });
      return false;
    };
    that.setData({
      userInfos: JSON.parse(my.getStorageSync({
        key: 'user', // 缓存数据的key
      }).data)
    })
    that.getData();
  },
  onReady() {
    // 页面加载完成
  },
  onShow() {
    // 页面显示
  },
  onHide() {
    // 页面隐藏
  },
  onUnload() {
    // 页面被关闭
  },
  onTitleClick() {
    // 标题被点击
  },
  onPullDownRefresh() {
    // 页面被下拉
  },
  onReachBottom() {
    // 页面被拉到底部
  },
  onShareAppMessage() {
    // 返回自定义分享信息
    return {
      title: my.getStorageSync({
        key: 'hotel_name', // 缓存数据的key
      }).data,
      desc: my.getStorageSync({
        key: 'my_app_description', // 缓存数据的key
      }).data,
      path: 'pages/index/index?share=true',
      success: function (e) {
        console.log(e);
      }
    };
  },
});
